package com.dolphin.aiagentplatform.ai.repository;

import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 基于内存的会话ID仓库
 */
@Component
public class InMemoryChatIdRepository implements ChatIdRepository {

    private final Map<String, List<String>> chatHistory = new HashMap<>();

    @Override
    public void save(String chatType, String chatId) {
        chatHistory.computeIfAbsent(chatType, v -> new ArrayList<>());
        List<String> chatIds = chatHistory.get(chatType);
        if (!chatIds.contains(chatId)) {
            chatIds.add(chatId);
        }
    }

    @Override
    public List<String> getChatIdList(String chatType) {
        return chatHistory.getOrDefault(chatType, List.of());
    }
}
